package libs.game;

/**
 *
 * @author      Jan Papousek
 * @version     2009-02-21
 */
public class Coordinates {

    private int x;

    private int y;

    /**
     * @param   x   Coordinate X.
     * @param   y   Coordinate Y.
     * @throws  IllegalArgumentException if some of the coordinates is minus.
     */
    public Coordinates(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return this.x;
    }

     public int getY() {
        return this.y;
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Coordinates)) {
            return false;
        }
        Coordinates coord = (Coordinates) o;
        return (coord.getX() == this.getX()) && (coord.getY() == this.getY());
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 17 * hash + this.x;
        hash = 17 * hash + this.y;
        return hash;
    }

    /**
     *          It check if the coordinate is in range
     *          <XrangeStart,XrangeEnd>,<YrangeStart,YrangeEnd>.
     *
     * @param   XrangeStart     Beginning of the X range.
     * @param   XrangeEnd       End of the X range.
     * @param   YrangeStart     Beginning of the Y range.
     * @param   YrangeEnd       End of the Y range.
     * @return  TRUE if the coordinate is in range, otherwise FALSE.
     * @throws  IllegalArgumentException if the range ends are less than range beginnings.
     */
    public boolean isInRange(int XrangeStart, int YrangeStart, int XrangeEnd, int YrangeEnd) {
        if (XrangeEnd < XrangeStart) {
            throw new IllegalArgumentException("The X range is invalid.");
        }
        if (YrangeEnd < YrangeStart) {
            throw new IllegalArgumentException("The Y range is invalid.");
        }
        if ((this.getX() < XrangeStart) || (this.getY() < YrangeStart)) {
            return false;
        }
        if ((this.getX() > XrangeEnd) || (this.getY() > YrangeEnd)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "[" + this.getX() + ";" + this.getY() + "]";
    }
}
